<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_804036_icvgng3gaxq.css">
    <link rel="stylesheet" href="../../css/member/setting.css">
</head>
<body>
<header id="header">
  设置
   <span class="left" onclick="api.closeWin()"><i class="iconfont icon-back"></i></span>
 </header>
 <section>
    <ul>
      <li>
        <span>头像</span>
        <p>
          <img src="../../image/beijing_03.png" alt="" onclick="showAction()" id="imgUp">
        </p>
      </li>
      <li>
        <span>昵称</span>
        <p><input type="text"></p>
      </li>
      <li>
        <span>手机号码</span>
        <p><input type="text"></p>
      </li>
      <li>
        <span>性别</span>
        <p><select class="" name="">
          <option value="0">男</option>
          <option value="1">女</option>
        </select></p>
      </li>
      <li>
        <span>出生日期</span>
        <p>
          <input type="text" onclick="this.blur()" id="Date">
          <input type="date" id="time" onchange="timeChange(this)">
        </p>
      </li>
      <li>
        <span>收货地址</span>
        <p><input type="text" onclick="openAddress(this)" id=“address” value=""></p>
      </li>
      <li>
        <span>详细地址</span>
        <p><input type="text"></p>
      </li>
    </ul>
    <div style="height:60px"></div>
    <p class="btn">确定</p>
 </section>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript">
  var citySelector=null;
  var addressVal=$api.byId('“address”')

  apiready=function () {
    citySelector = api.require('citySelector');
  }

    //选择地址
    function openAddress(self){
      self.blur();
      citySelector.open({
      y: api.frameHeight / 1.6,
      fixedOn: api.frameName
      }, function(ret) {
        var res='';
        var arr=[]
        for(var i in ret){
          res+=ret[i]
        }
        addressVal.value=res
      });
    }
    //选择时间
    function timeChange(self) {
      var value=self.value;
      $api.byId('Date').value=value;

    }
    //上传图片
    function showAction(){
        api.actionSheet({
            title: '上传图片',
            cancelTitle: '取消',
            buttons: ['拍照','从手机相册选择']
        }, function(ret, err) {
            if (ret) {
                getPicture(ret.buttonIndex);
            }
        });
    }
    function getPicture(sourceType) {
        if(sourceType==1){ // 拍照
            api.getPicture({
                sourceType: 'camera',
                encodingType: 'jpg',
                mediaValue: 'pic',
                allowEdit: false,
                destinationType: 'base64',
                quality: 90,
                saveToPhotoAlbum: true
            }, function(ret, err) {
                if (ret) {
                   $('#imgUp').attr('src', ret.base64Data);
                }else {
                    alert(JSON.stringify(err));
                }
            });
        }
        else if(sourceType==2){ // 从相机中选择
            api.getPicture({
                    sourceType: 'library',
                    encodingType: 'jpg',
                    mediaValue: 'pic',
                    destinationType: 'base64',
                    quality: 50,
                    targetWidth: 750,
                    targetHeight: 750
                }, function(ret, err) {
                    if (ret) {
                        // $('#imgUp').attr('src', ret.base64Data)
                        var aa=ret.base64Data;

                        $('#imgUp').attr('src',aa)
                        // api.ajax({
                        //     type:"post",
                        //     url:"http://www.yuechebang.cn/Oauth/Api/index",
                        //     data:{base64:aa},
                        //     dataType:'json',
                        //     async:true,
                        // },function(ret,err){
                        //     if(ret){
                        //         $('#imgUp').attr('src',aa)
                        //     }else{
                        //         api.alert(err);
                        //     }
                        // })
                    } else {
                        alert(JSON.stringify(err));
                    }
            });
        }
      }
</script>
</html>
